package com.frxuexi.park2212.hourse

import android.view.View
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.MyHourseBean
import com.frxuexi.park2212.R

class HourseAreaAdapter(vm:HourseViewModel):BaseQuickAdapter<MyHourseBean,BaseViewHolder>(R.layout.item_earahouse) {
    lateinit var vm:HourseViewModel
    init {
        this.vm=vm
    }
    override fun convert(helper: BaseViewHolder, item: MyHourseBean) {
        helper.setText(R.id.tv01,"${item.dong}栋")
        helper.setText(R.id.hourse_area,"${item.area}m²")

        val hourseAdapter by lazy { HourseAdapter(vm) }
        hourseAdapter.addData(item.list)
        val rv = helper.getView<RecyclerView>(R.id.rv_01)
        rv.apply {
            adapter = hourseAdapter
            layoutManager = LinearLayoutManager(context,RecyclerView.HORIZONTAL,false)
        }

        helper.getView<ImageView>(R.id.more01).apply {
            setOnClickListener {
                if(rv.visibility==View.GONE){
                    rv.visibility=View.VISIBLE
                    setImageResource(R.drawable.ic_action_up)
                }else{
                    rv.visibility=View.GONE
                    setImageResource(R.drawable.ic_action_low)
                }
            }
        }

    }
}